package cn.blbsz.shop.domain.p;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import lombok.Getter;
import lombok.Setter;

/**
 * Created by Lenovo on 2017/3/28.
 */
@Entity
@Table(name = "t_user")
@Getter
@Setter
public class UserEntity implements Serializable {

    private static final long serialVersionUID = -6635686829321492581L;

    @Id
    @GenericGenerator(name = "idGenerator", strategy = "cn.blbsz.shop.utils.IdGenerator")
    @GeneratedValue(generator = "idGenerator")
    private Long userId;

    private String nickName;

    private String tel;
    private String password;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "pid", foreignKey = @ForeignKey(name = "none"))
    private UserEntity parent;

    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "t_user_t_role", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")})
    private List<RoleEntity> roleEntities = new ArrayList<>();

    private Integer openId;
    private String unionId;
    private Integer leftId;
    private Integer rightId;
    private Integer level;


}
